package me.shiqiang.im.linsteners;

import com.aliyun.openservices.ons.api.Producer;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.annotation.OnEvent;
import me.shiqiang.im.enums.MessageCmd;
import me.shiqiang.im.msg.SyncFriendReq;
import me.shiqiang.im.msg.SyncFriendResp;
import me.shiqiang.im.server.ConnectionContext;
import me.shiqiang.im.service.OptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author cuishiqiang
 * @date 2017/12/13 上午10:16
 */
@Component("FriendListener")
public class FriendListener extends Listener{
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    StringRedisTemplate redisTemplate;

    @Value("${server.id}")
    private String serverId;

    @Value("${com.tst.rocketmq.producer.topic}")
    private String topic;

    @Autowired
    OptService optService;

    @OnEvent("syncFriendReq")
    public void getFriends(SocketIOClient client, AckRequest request, SyncFriendReq msg) {

        SyncFriendResp resp = optService.processFriendSyncReq(msg.getUserId());
        client.sendEvent(MessageCmd.SYNC_FRIEND_RESP, resp);
    }

}
